package com.lbw.controller.chatHistory;

import com.lbw.chatMemory.MySqlRAGChatMemory;
import com.lbw.chatMemory.repository.MySqlRAGMemoryRepository;
import org.springframework.ai.chat.messages.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/pdfChatHistory")
public class RAGChatHistoryController {

    @Autowired
    private MySqlRAGChatMemory mySqlRAGChatMemory;

    @Autowired
    private MySqlRAGMemoryRepository mySqlRAGMemoryRepository;

    /**
     * 获取所有会话列表
     * @return
     */
    @GetMapping("/findConversationList")
    public List<String> getAllConversation(){
        return mySqlRAGMemoryRepository.findConversationIds();
    }

    /**
     * 根据会话id查询会话记录
     * @param conversationId
     * @return
     */
    @GetMapping("/findHistory")
    public List<Message> findHistory(String conversationId){
        return mySqlRAGChatMemory.get(conversationId);
    }

    /**
     * 根据会话Id删除会话记录
     * @param conversationId
     */
    @DeleteMapping("/deleteHistory")
    public void deleteHistory(String conversationId){
        mySqlRAGChatMemory.clear(conversationId);
    }
}
